/*
 * @Author: liucc
 * @Date: 2020-09-10 09:32:23
 * @LastEditors: liucc
 * @LastEditTime: 2021-01-22 18:26:35
 * @Description: 主配置文件
 */
/* eslint valid-jsdoc: "off" */

'use strict'

/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = (appInfo) => {
  /**
   * built-in config
   * @type {Egg.EggAppConfig}
   **/
  const config = (exports = {})

  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1599701477556_857'

  // add your middleware config here
  config.middleware = []

  // 配置 printdate 中间件参数
  config.printdate = {
    a: 111,
    b: 222,
  }

  // add your user config here
  const userConfig = {
    // myAppName: 'egg',
  }

  // passportJwt 配置
  config.passportJwt = {
    secret: '12345699090909090',
  }

  // csrf 安全相关配置 (如果是前后端分离，egg.js 作为 api 接口，则关闭 csrf 验证)
  config.security = {
    csrf: {
      enable: false,
      ignoreJSON: true,
    },
    // 运行域名白名单
    domainWhiteList: ['*'],
  }

  // 跨域相关配置
  config.cors = {
    origin: '*', // 匹配规则  域名+端口  *则为全匹配
    allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH',
  }

  // 配置上传
  config.multipart = {
    fileSize: '50mb',
    mode: 'stream',
    whitelist: ['.doc', '.docx', '.xls', '.xlsx', '.jpg', '.png', '.zip'], // 扩展几种上传的文件格式
  }
  // mysql 配置
  config.mysql = {
    //database configuration
    client: {
      //host
      host: 'localhost',
      //port
      port: '3306',
      //username
      user: 'root',
      //password
      password: 'jianpan',
      //database
      database: 'manage-recorder',
    },
    //load into app,default is open //加载到应用程序，默认为打开
    app: true,
    //load into agent,default is close //加载到代理中，默认值为“关闭”
    agent: false,
  }

  // 测试爬虫的网址
  config.testApiUrl = 'http://www.phonegap100.com'
  // http://www.phonegap100.com/appapi.php?a=getPortalList&catid=20&page=1

  return {
    ...config,
    ...userConfig,
  }
}
